//
//  RouteScheduleTableViewCell.m
//  EDPS
//
//  Created by 张维扬 on 15/11/27.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "RouteScheduleTableViewCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface RouteScheduleTableViewCell ()
@property (nonatomic, retain) UILabel *topLabel;//上面蓝条
@property (nonatomic, retain) UILabel *botomLabel; // 下面灰条
@property (nonatomic, retain) UILabel *seeRouteLabel;
@property (nonatomic, retain) UIImageView *icon; // 国旗图片
@property (nonatomic, retain) UILabel *cities;//城市名字
@property (nonatomic, retain) NSString *appendingStr; // 拼接城市名字字符串
@end

@implementation RouteScheduleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.topLabel = [[UILabel alloc] init];
        self.topLabel.backgroundColor = RGB(62, 176, 190);
        [self.contentView addSubview:self.topLabel];
        
        self.botomLabel = [[UILabel alloc] init];
        self.botomLabel.backgroundColor = RGB(188, 187, 192);
        [self.contentView addSubview:self.botomLabel];
    
        self.icon = [[UIImageView alloc] init];
        [self.contentView addSubview:self.icon];
        self.icon.layer.cornerRadius = 15;
        self.icon.clipsToBounds = YES;
        
        self.cities = [[UILabel alloc] init];
        [self.cities setFont:[UIFont systemFontOfSize:16]];
        self.cities.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:self.cities];
        
        
        self.seeRouteLabel = [[UILabel alloc] init];
        self.seeRouteLabel.text = @"查看线路日程";
        self.seeRouteLabel.textColor = [UIColor lightGrayColor];
        self.seeRouteLabel.textAlignment = NSTextAlignmentCenter;
        self.seeRouteLabel.backgroundColor = RGB(239, 239, 239);
        [self.contentView addSubview:self.seeRouteLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.contentView.frame = CGRectMake(10, 0, self.frame.size.width - 20, self.frame.size.height);
    // 上面条
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth - 20, 3));
    }];
    // 下面条
    [self.botomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth - 20, 3));
        
    }];
    // 查看线路
    [self.seeRouteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.botomLabel.mas_top).offset(-0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth - 20, ScreenWidth * 0.07));
    }];
    // 国旗图片
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.seeRouteLabel.mas_top).offset(-10);
        make.left.mas_equalTo(self.contentView.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    // 城市名字
    [self.cities mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.icon.mas_centerY);
        make.left.mas_equalTo(self.icon.mas_right).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth - 20, 30));
    }];
    
}
- (void)setModel:(DetailTravelModel *)model
{
    if (_model != model) {
        _model = model;
    }
    if (![model.icon isEqualToString:@""]) {
        [self.icon sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:[UIImage imageNamed:@"hold"]];
        
    }
}
- (void)setCitiesArr:(NSArray *)citiesArr
{
    if (_citiesArr != citiesArr) {
        _citiesArr = citiesArr;
    }
    
    self.appendingStr = [[NSString alloc] init];
    if (self.citiesArr.count != 0) {
        for (NSInteger i = 0; i < self.citiesArr.count; i++) {
            NSString *str = [NSString stringWithFormat:@"%@ ·", self.citiesArr[i]];
            self.appendingStr = [self.appendingStr stringByAppendingString:str];
        }
        self.cities.text = self.appendingStr;
    }
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
